<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>日常分享管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--列表-->
    <el-table size="small" :data="daityList" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 80%;">
      <el-table-column align="center" prop="id" label="分享ID" width="150">
      </el-table-column>
      <el-table-column align="center" prop="userName" label="分享用户" width="150">
      </el-table-column>
      <el-table-column align="center" prop="img" label="分享图" width="150">
        <template slot-scope="scope" v-if="scope.row.img">
          <el-image
            style="width: 100px"
            :src="scope.row.img"
            fit="contain"></el-image>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" prop="content" label="分享内容" width="150"></el-table-column>
      <el-table-column align="center" prop="createTime" label="分享日期" width="150">
        <template slot-scope="scope">
          {{scope.row.createTime | timeFilter}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteDaity(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageQuery" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
export default {
  name:'DaityDaity',
  data() {
    return {
      good: {},
      dialog: false, 
      daityList: [], // 分享列表
      pageQuery: {
        pageNum: 1,
        pageSize: 10
      },
      loading: false //是显示加载
    }
  },
  filters: {
    timeFilter (val) {
      return val.match(/.+(?=\.)/g)[0].replace('T', ' ')
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getDaityList()
  },
  methods: {
    /**
     * 获取用户列表
     */
    getDaityList() {
      this.loading = true
      this.$api.daity.getDaityList(this.pageQuery).then(res => {
        if (res.code === 200) {
          this.daityList = res.data.records
          this.loading = false
        }
      }).catch(err => this.loading = false)
    },
    /**
     * 删除分享
     */
    deleteDaity (index, daity) {
      let params = {
        id: daity.id
      }
      this.$api.daity.deleteDaity(params).then(res =>{
        if (res.code === 200) {
          this.getDaityList()
        }
      })
    },
    /**
     * 分页插件事件
     */
    callFather(parm) {
      this.pageQuery.pageNum = parm.currentPage
      this.pageQuery.pageSize = parm.pageSize
      this.getDaityList()
    }
  }
}
</script>

<style>
.comment-search {
  margin-top: 20px;
}
.commentRole {
  width: 100%;
}
</style>

 
 